<!DOCTYPE html>
<html>

<head>
    <title>酒店列表</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travel.css"/>
    <script src="/js/plugins/jrender/jrender.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog/dialog.css">
    <link rel="stylesheet" href="dropDown/reset.css">
    <link rel="stylesheet" href="dropDown/style.css">
    <script src="/js/plugins/dialog/dialog.min.js"></script>
    <script src="/js/common.js"></script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>

        <div class="col-8">
            <div class="input-group-sm search">
                    <input class="form-control searchBtn" placeholder="搜商品">
            </div>
        </div>
        <div class="col-2">
            <div class="input-group-sm">
                <!--<button id="hotelSearch">搜索</button>-->
                <input type="submit" value="搜   索" class="btn-search " id="hotelSearch">
            </div>
        </div>
    </div>
</div>


<div class="container">
    <h6>很贵的商品</h6>
    <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
        <div id="travelsCommends" class="carousel-inner" render-loop="list">
            <div class="carousel-item">
                <div class="border commend">
                    <a role="button" render-key="list.id" render-fun="handle">
                        <img render-src="list.coverUrl"widht="100"  height="300">
                        <h3 render-html="list.name"></h3>
                        <!--<small render-html="list.placeName"></small>-->
                    </a>
                </div>
            </div>
        </div>

        <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
    </div>
</div>









<div class="container hotels">
    <h6>全部商品</h6>
    <div id="allHotels" render-loop="list">
        <div class="row detail">
            <div class="col bigimg">
                <a href="hotelContent.html" render-key="list.id" render-fun="handle">
                    <img render-src="list.coverUrl" widht="100"  height="150">
                </a>
            </div>
            <div class="col">
                <a href="hotelContent.html" render-key="list.id" render-fun="handle">
                    <h3 render-html="list.name"></h3>
                </a>
                <p>
                    类型:<span render-html="list.productTypeName"></span>
                </p>
                <p>
                    <img class="rounded-circle head-img" render-src="list.coverUrl">
                    <span render-html="list.name"></span>
                    <br/>
                    积分价格:<span render-html="list.integral"></span>
                    <br/>
                </p>
            </div>
        </div>
    </div>
</div>

<script>
    var currentPage = 1;
    var pages;
    var hotels;
    /*var hotelId = getParams().id;
    console.log(hotelId);*/

    $(function () {


        //查询很贵的商品
        $.get("/products/money",function (data) {
            $("#carouselExampleControls").renderValues({list:data},{
                handle:function (ele,value) {
                    $(ele).attr("href","/shop/detail.html?id=" + value);
                }
            })
            //注意坑点,这个不用渲染不出来
            $("#travelsCommends>div:first").addClass("active");
        });


        //查所有商品
        $.get("/products/listAll",{pageSize:3},function (data) {
            renderView(data);
            pages=data.pages;
            hotels=data.list;
        },"json");

        $(window).scroll(function () {
            if (isEnd()) {
                if (currentPage < pages) {
                    currentPage++;
                    $.get("/products/listAll", {
                        currentPage: currentPage,
                        pageSize: 2
                    }, function (data) {
                        $.merge(hotels, data.list);
                        renderView({list: hotels});
                    }, "json");
                }else {
                    $(document).dialog({
                        type: "notice",
                        infoText: "已经到底部了",
                        autoClose: 1500,
                        position: "center"
                    });
                }
            }
        })


        //点击搜商品按钮
        $("#hotelSearch").click(function () {
            //要获取input里面的内容然后作为参数给ajax请求
            var keyword =  $(".searchBtn").val();
            //发送ajax请求查询对应名称酒店
            $.get("/products/byName",{keyword:keyword,pageSize:5},function (data) {
                console.log(data);
                //渲染界面
                renderView(data);
                pages=data.pages;
                hotels=data.list;
            },"json");

            $(window).scroll(function () {
                if(isEnd()){
                    console.log("--");
                    if(currentPage<pages){
                        currentPage++;
                        $.get("/products/byName",{currentPage:currentPage,keyword:keyword,pageSize:5},function (data) {
                            $.merge(hotels,data.list);
                            console.log(hotels);
                            renderView({list:hotels});
                        },"json");
                    }else{
                        $(document).dialog({
                            type:"notice",
                            infoText:"已经到底部了",
                            autoClose:1500,
                            position:"center"
                        });
                    }
                }
            })

        })


    })

    function renderView(data) {
        $(".hotels").renderValues(data,{
            handle:function (ele,value) {
                $(ele).attr("href","shop/detail.html?id=" + value);
            }
        })
    }
</script>

</body>

</html>